package com.example.gamestore.control;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.gamestore.Bean.Game;
import com.example.gamestore.mapper.GameMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

@Controller
public class SearchControl {
    @Autowired
    private GameMapper gameMapper;
    @GetMapping("/search")
    public String search(String gamename, Model model){
        LambdaQueryWrapper<Game> wrapper=new LambdaQueryWrapper<>();
        wrapper.like(Game::getGamename,gamename);
        List<Game> games = gameMapper.selectList(wrapper);
        if(!(games.isEmpty())){
            model.addAttribute("games",games);
            return "Search/GamesSearch";
        }
        model.addAttribute("error","未查询到该游戏");

        return "Search/GamesSearch";
    }
}
